<?php
	include("../../include/dbconnect.php");
	
	$table="menunhom";
	session_start();
	header('Content-type: application/json; charset=utf-8');
	if(!isset($_SESSION["un"])) $_SESSION["un"]="";
	if($_SESSION["un"]=="")
		echo "{\"status\":0,\"msg\" : \"Chưa đăng nhập !\"}";
	else if($_POST["id"]=="0")
		echo "{\"status\":0,\"msg\" : \"Không phải nhóm !\"}";
	else
	{
		$found=false;
		$rs=mysql_query("select * from $table where id<>".$_POST["id"]." and ten='".$_POST["ten"]."'",$conn);
		$found=(mysql_num_rows($rs)>0);
		mysql_free_result($rs);
		if($found)
		{
			echo "{\"status\":0,\"msg\":\"Đã có nhóm menu tên ".$_POST["ten"]."\"}";
			die();
		}
		mysql_query("update $table set ten='".$_POST["ten"]."' where id=".$_POST["id"],$conn);
		echo "{\"status\":1,\"msg\" : \"\"}";
	}
	
	include("../../include/dbclose.php");
?>
